const PATH_LINK = 'link';
+
+ /**
+ * A version ID that identifies the serialization structure used by getSerializationData()
+ * and unserialize(). This is useful for constructing cache keys in cases where the cache relies
+ * on serialization for storing the SiteList.
+ *
+ * @var string A string uniquely identifying the version of the serialization structure.
+ */
+ const SERIAL_VERSION_ID = '2013-01-23';
+
/**
* @since 1.21
*
return $group;
}
+ /**
+ * A version ID that identifies the serialization structure used by getSerializationData()
+ * and unserialize(). This is useful for constructing cache keys in cases where the cache relies
+ * on serialization for storing the SiteList.
+ *
+ * @var string A string uniquely identifying the version of the serialization structure,
+ * not including any sub-structures.
+ */
+ const SERIAL_VERSION_ID = '2013-01-23';
+
+ /**
+ * Returns the version ID that identifies the serialization structure used by
+ * getSerializationData() and unserialize(), including the structure of any nested structures.
+ * This is useful for constructing cache keys in cases where the cache relies
+ * on serialization for storing the SiteList.
+ *
+ * @return string A string uniquely identifying the version of the serialization structure,
+ * including any sub-structures.
+ */
+ public static function getSerialVersionId() {
+ return self::SERIAL_VERSION_ID . '+Site:' . Site::SERIAL_VERSION_ID;
+ }
+
/**
* @see GenericArrayObject::getSerializationData
*
* @return array
*/
protected function getSerializationData() {
+ //NOTE: When changing the structure, either implement unserialize() to handle the
+ // old structure too, or update SERIAL_VERSION_ID to kill any caches.
return array_merge(
parent::getSerializationData(),
array(
*/
protected $sitesTable;
+ /**
+ * @var string|null
+ */
+ private $cacheKey = null;
+
/**
* @since 1.21
*
$this->sitesTable = $sitesTable;
}
+ /**
+ * Constructs a cache key to use for caching the list of sites.
+ *
+ * This includes the concrete class name of the site list as well as a version identifier
+ * for the list's serialization, to avoid problems when unserializing site lists serialized
+ * by an older version, e.g. when reading from a cache.
+ *
+ * The cache key also includes information about where the sites were loaded from, e.g.
+ * the name of a database table.
+ *
+ * @see SiteList::getSerialVersionId
+ *
+ * @return String The cache key.
+ */
+ protected function getCacheKey() {
+ if ( $this->cacheKey === null ) {
+ $type = 'SiteList#' . SiteList::getSerialVersionId();
+ $source = $this->sitesTable->getName();
+
+ if ( $this->sitesTable->getTargetWiki() !== false ) {
+ $source = $this->sitesTable->getTargetWiki() . '.' . $source;
+ }
+
+ $this->cacheKey = wfMemcKey( "$source/$type" );
+ }
+
+ return $this->cacheKey;
+ }
+
/**
* @see SiteStore::getSites
*
if ( $source === 'cache' ) {
if ( $this->sites === null ) {
$cache = wfGetMainCache();
- $sites = $cache->get( wfMemcKey( 'SiteList' ) );
+ $sites = $cache->get( $this->getCacheKey() );
if ( is_object( $sites ) ) {
$this->sites = $sites;
}
$cache = wfGetMainCache();
- $cache->set( wfMemcKey( 'SiteList' ), $this->sites );
+ $cache->set( $this->getCacheKey(), $this->sites );
}
/**